package com.eonmind.user.dto;

import com.eonmind.common.contract.data.request.PageRequest;
import com.eonmind.common.contract.enums.user.PasswordComplexity;
import com.eonmind.common.contract.enums.user.UserGender;
import com.eonmind.common.contract.enums.user.UserLoginStatus;
import com.eonmind.common.contract.timer.Timer;
import com.eonmind.common.provider.entity.user.UserLoginRecord;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;


public class UserDto {
    /**
     * 用户登录请求
     */
    @Data
    @ToString
    public static class UserLoginRequest {
        /**
         * 用户名
         *
         * @mock testUser1
         */
        private String username;
        /**
         * 邮箱
         */
        @Email(message = "邮箱格式错误")
        private String email;
        /**
         * 手机号
         */
        @Length(min = 11, max = 11)
        private String phone;
        /**
         * 密码
         *
         * @mock 123456
         */
        @NotBlank(message = "密码不能为空")
        private String password;
    }

    /**
     * 登录响应
     */
    @Data
    @ToString
    public static class UserLoginResponse {
        /**
         * 用户名
         */
        private String userName;

        /**
         * 头像地址
         */
        private String headshot;

        /**
         * 电话号码
         */
        private String phoneNumber;

        /**
         * 邮箱
         */
        private String email;

        /**
         * 真实姓名
         */
        private String realName;

        /**
         * 性别 0-男 1-女
         */
        private Integer sex = UserGender.MAN.getCode();

        /**
         * 密码强度
         */
        private Integer passwordComplexity = PasswordComplexity.Low.getCode();

        /**
         * 用户Token
         */
        private String token;
    }

    /**
     * 用户注册请求
     */
    @Data
    @ToString
    public static class UserRegisterRequest {
        /**
         * 用户名
         *
         * @mock test
         */
        @NotBlank(message = "用户名不能为空")
        private String username;
        /**
         * 密码
         *
         * @mock 123456
         */
        @NotBlank(message = "密码不能为空")
        private String password;
        /**
         * 邮箱
         *
         * @mock 12345@163.com
         */
        @Email(message = "邮箱格式错误")
        @NotBlank(message = "邮箱不可为空")
        private String email;
        /**
         * 电话号码
         *
         * @mock 12345678901
         */
        @Pattern(message = "电话号码错误", regexp = "^1[3-9]\\\\d{9}$")
        @NotBlank(message = "电话号码不可为空")
        private String phoneNumber;
        /**
         * 性别
         *
         * @mock 男
         */
        @NotBlank(message = "性别不可为空")
        private Integer sex = UserGender.MAN.getCode();
        /**
         * 验证码
         *
         * @mock 123456
         */
        @NotBlank(message = "验证码不可为空")
        private String verificationCode;
        /**
         * 密码强度
         */
        private Integer passwordComplexity = PasswordComplexity.Low.getCode();
    }

    @Data
    @ToString
    public static class UserUpdateRequest {
        /**
         * 邮箱
         *
         * @mock 3285503539@qq.com
         */
        @Email(message = "邮箱格式错误")
        @NotBlank(message = "邮箱不可为空")
        private String email;
        /**
         * 新密码
         *
         * @mock 1234567
         */
        @NotBlank(message = "新密码不可为空")
        private String newPassword;
        /**
         * 验证码
         *
         * @mock 123456
         */
        @NotBlank(message = "验证码不可为空")
        private String verificationCode;

        /**
         * 密码强度
         */
        private Integer passwordComplexity = PasswordComplexity.Low.getCode();

    }

    @Data
    @ToString
    public static class SendEmailCodeRequest {
        /**
         * 邮箱
         *
         * @mock 3285503539@qq.com
         */
        @Email(message = "邮箱格式错误")
        @NotBlank(message = "邮箱不可为空")
        private String email;
    }

    @Data
    @ToString
    public static class UserLoginRecordData {
        /**
         * 主键ID
         */
        private Long id;

        /**
         * 用户ID
         */
        private Long userId;

        /**
         * 登录时间
         */
        private Long loginTime = Timer.currentTimestamp();

        /**
         * 登录IP
         */
        private String loginIp;

        /**
         * 登录地点
         */
        private String loginLocation;

        /**
         * 登录设备
         */
        private UserLoginRecord.DeviceInfo loginDevice;

        /**
         * 登录状态(0-失败 1-成功)
         */
        private Integer loginStatus = UserLoginStatus.SUCCESS.getCode();

    }

    @Data
    @ToString
    public static class UserLoginRecordPageRequest {
        /**
         * 分页参数
         */
        private PageRequest page = new PageRequest();
    }
}